/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package its.mx.dsw2.view;

import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ActionEvent;
import mx.its.dsw2.Bl.CourseBLLocal;
import mx.itsc.ds2.model.Course;

/**
 *
 * @author Martinez
 */
@ManagedBean
@SessionScoped
public class CourseBean {
    //...................EJB...................//

    @EJB
    private CourseBLLocal courseBL;
    //...................Variables............//
    private List<Course> courseList;
    private Course course;
    private String action;

    //...................Constructores........//
    public CourseBean() {
    }

    //...................Acciones.............//
    public void prepareNew(ActionEvent evt) {
        action = "New";
        course = new Course();
    }

    public String processAction() {
        if (action.equalsIgnoreCase("New")) {
            courseBL.register(course);
        } else if (action.equalsIgnoreCase("Edit")) {
            courseBL.modify(course);
        } else if (action.equalsIgnoreCase("Delete")) {
            courseBL.remove(course);
        }
        action = "";
        return "CourseList";
    }
    
    public void prepareEdit(ActionEvent evt){
        action = "Edit";
        courseList = courseBL.findCourse(course);
    }
    //..................Getters y Setters.....//

    public List<Course> getCourseList() {
        courseList = courseBL.findAll();
        return courseList;
    }

    public void setCourseList(List<Course> courseList) {
        this.courseList = courseList;
    }

    public Course getCourse() {
        return course;
    }

    public void setCourse(Course course) {
        this.course = course;
    }
}
